<template>
<el-table :data="arr">
  <el-table-column type="index" label="编号" width="100px"></el-table-column>
  <el-table-column label="轮播图">
    <template #default="scope">
      <img :src="BASE_URL+scope.row.imgUrl" style="width: 200px">
    </template>
  </el-table-column>
  <el-table-column prop="createTime" label="发布时间"></el-table-column>
  <el-table-column label="操作">
    <template #default="scope">
      <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
    </template>
  </el-table-column>
</el-table>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
  const del = (i,banner)=>{
    if (confirm("您确认删除此轮播图吗?")){
      axios.post(BASE_URL+"/v1/banners/"+banner.id+"/delete").then((response)=>{
        if (response.data.code==2001){
          ElMessage.success("删除成功!");
          arr.value.splice(i,1);
        }
      })
    }
  }
  const arr = ref([]);

  onMounted(()=>{
    axios.get(BASE_URL+"/v1/banners/admin").then((response)=>{
      if (response.data.code==2001){
        arr.value = response.data.data;
      }
    })
  })
</script>

<style scoped>

</style>